package com.tianhui.consignortwofei.other.auth.state;

import android.content.Context;

import com.tianhui.consignortwofei.mvp.model.enty.RecognitionInfo;
import com.tianhui.consignortwofei.mvp.model.enty.SelectPhotoInfo;
import com.tianhui.consignortwofei.other.auth.inte.ProcessCallback;
import com.tianhui.consignortwofei.other.auth.inte.RecognitionCallback;
import com.tianhui.consignortwofei.other.auth.inte.SelectPhotoCallback;
import com.tianhui.consignortwofei.other.auth.ocr.IOcrRecognition;
import com.tianhui.consignortwofei.other.auth.recognition.process.IRecognitionProcess;


/**
 * @author fgs
 * @date 2021/5/13
 * @description 识别
 **/
public class RecognitionState<T> implements IPictureProcessState {
    private IOcrRecognition iOcrRecognition;
    private IRecognitionProcess iRecognitionProcess;

    public RecognitionState(IOcrRecognition iOcrRecognition, IRecognitionProcess iRecognitionProcess) {
        this.iOcrRecognition = iOcrRecognition;
        this.iRecognitionProcess = iRecognitionProcess;
    }

    @Override
    public void stateProcess(Context context, SelectPhotoInfo selectPhotoInfo, SelectPhotoCallback callback) {
        iOcrRecognition.recognition().recognition(context, selectPhotoInfo, new RecognitionCallback() {
            @Override
            public void recognitionSuccess(RecognitionInfo recognitionInfo) {
                iRecognitionProcess.recognitionProcess(recognitionInfo, selectPhotoInfo, new ProcessCallback<T>() {
                    @Override
                    public void processSuccess(T t) {
                        selectPhotoInfo.resultInfo = t;
                        callback.selectPhotoSuccess(selectPhotoInfo);
                    }

                    @Override
                    public void processFailed() {
                        callback.selectPhotoFailed();
                    }
                });
            }

            @Override
            public void recognitionFailed() {
                callback.selectPhotoFailed();
            }
        });
    }
}
